package com.wwfish.cmsui.modules.sysuser.client.widget;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.nexustar.gwt.dashboard.client.MenuModel;
import com.nexustar.gwt.dashboard.client.MenusFactory;
import com.nexustar.gwt.dashboard.client.PageModel;
import com.nexustar.gwt.widgets.client.asyn.IAsyncModelCallback;
import com.nexustar.gwt.widgets.client.ui.iprovider.ITreeProvider;
import com.nexustar.gwt.widgets.client.ui.table.CheckBoxViewTable;
import com.nexustar.gwt.widgets.client.ui.tree.CheckBoxTree;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2010-8-19
 * Time: 9:56:18
 * To change this template use File | Settings | File Templates.
 */
public class AccessFunctionTreeWidget extends Composite {
    private CheckBoxTree tree;
    private ITreeProvider provider = new ITreeProvider() {
        public String getTreeItemText(Object entity) {
            if (entity instanceof MenuModel)
                return ((MenuModel) entity).getText();
            else
                return ((PageModel) entity).getPageTitle();
        }

        public Image getTreeItemIcon(Object entity) {
            return null;
        }

        public boolean hasChildren(Object entity) {
            if (entity instanceof MenuModel)
                return ((MenuModel) entity).getPages() != null && ((MenuModel) entity).getPages().size() > 0;
            else
                return ((PageModel) entity).getChildren() != null && ((PageModel) entity).getChildren().size() > 0;
        }

        public void getChildren(Object entity, IAsyncModelCallback asyn) {
            if (entity instanceof MenuModel)
                asyn.setModelElments(((MenuModel) entity).getPages());
            else
                asyn.setModelElments(((PageModel) entity).getChildren());
        }

        public void setInputData(Object[] paramters, IAsyncModelCallback asyn) {
//            callback.setModelElments(asyn);
//            asyn.setModelElments(MenusFactory.getInstance().getMenu());
        }
    };

    public AccessFunctionTreeWidget() {
        tree = new CheckBoxTree(provider, CheckBoxTree._CASCADE_PARENT);
        initWidget(tree);
    }

    public CheckBoxTree getTree() {
        return tree;
    }
}
